package com.yb.bussiness.goods;

import java.util.List;
import java.util.Map;
import com.yb.base.dao.BaseDao;
import com.yb.base.dao.IBaseDao;
import com.yb.domain.goods.TgPart;

public class TgPartServiceImpl implements TgPartService {
	private IBaseDao<TgPart, Long> dao;

	public TgPartServiceImpl() {
		dao = new BaseDao<TgPart, Long>(TgPart.class);
	}

	public void isSave(TgPart tgPart) {
		dao.saveOrUpdate(tgPart);
	}

	public int count(Map<String, String> parameMap) {
		try {
			String str = "  SELECT  * FROM t_g_part  ";
			List<TgPart> list = dao.findList(str);
			if (list != null) {
				return list.size();
			}
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
		return 0;
	}

	public boolean deleteById(String ids) {

		if ("".equals(ids))
			return false;
		String sql = "";
		String[] delteid = ids.split("_");
		try {
			for (int i = 0; i < delteid.length; i++) {
				sql = "delete  from t_g_part where  id=" + delteid[i];
				dao.delete(sql);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}

		return true;
	}

	public List<TgPart> findByParameMap(Map<String, String> parameMap) {
		String str = " SELECT  * from t_g_part  where 1=1 ";
		if (parameMap.get("auding") != null && !"".equals(parameMap.get("auding"))) {
			str += " and auding = '"+parameMap.get("auding")+"' ";
		}
		if (parameMap.get("page") != null && parameMap.get("row") != null) {
			int start = Integer.parseInt(parameMap.get("page")) - 1;
			int limit = Integer.parseInt(parameMap.get("row"));
			str += " limit " + start * limit + "," + limit;
		}
		return dao.findList(str);

	}

	public boolean updateAutingId(String id, String autding) {
		try {
			String sql = " UPDATE   t_g_part t set t.auding=" + autding
					+ " WHERE t.id= " + id;
			dao.update(sql);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	public Integer getCount() {
		String sql = "select count(*) from t_g_part where auding = '0' or auding is null order by id desc";
		int total = Integer
		.parseInt((dao.findObjectArryList(sql).get(0))[0]
				.toString());
		return total;
	}

	public List<TgPart> findByTime(String time) {
		String sql = "select * from t_g_part where auding = '0' or auding is null order by id desc";
		List<TgPart> list = dao.findList(sql);
		return list;
	}

}
